package com.xiaoming.api;

import com.xiaoming.service.HelloService;
import org.apache.dubbo.config.annotation.Reference;
import org.apache.dubbo.rpc.RpcContext;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@RestController
public class HelloController {
    @Reference(loadbalance = "roundrobin")
    private HelloService helloService;

    @GetMapping("/hello")
    public String sayHello(HttpServletRequest request) {
        String clientIp = request.getRemoteAddr();
        RpcContext.getContext().set("clientIp", clientIp);
        String res = helloService.sayHello();
        System.out.println("返回信息：" + res);
        return res;
    }
}
